package org.lex.jdbc.url.view.internal;

import javax.swing.tree.DefaultMutableTreeNode;

import org.lex.jdbc.url.DriverConfig;
import org.lex.jdbc.url.Session;

public class JdbcConnectionTreeNode extends DefaultMutableTreeNode {
	public static enum NodeType {
		TEXT() {

			@Override
			public String getLabel(Object userObject) {
				return String.valueOf(userObject);
			}
		},
		DRIVER() {

			@Override
			public String getLabel(Object userObject) {
				return ((DriverConfig) userObject).getName();
			}
		},
		SESSION() {

			@Override
			public String getLabel(Object userObject) {
				return ((Session) userObject).getName();
			}
		};

		public abstract String getLabel(Object userObject);
	}

	private final NodeType nodeType;
	private final boolean editable;

	public JdbcConnectionTreeNode(NodeType nodeType, boolean editable) {
		super();
		this.nodeType = nodeType;
		this.editable = false;
	}

	public JdbcConnectionTreeNode(Object userObject, NodeType nodeType,
			boolean editable) {
		super(userObject);
		this.nodeType = nodeType;
		this.editable = false;
	}

	public JdbcConnectionTreeNode(Object userObject, boolean allowsChildren,
			NodeType nodeType, boolean editable) {
		super(userObject, allowsChildren);
		this.nodeType = nodeType;
		this.editable = false;
	}

	public NodeType getNodeType() {
		return nodeType;
	}

	public boolean isEditable() {
		return editable;
	}

	public String toString() {
		return this.getNodeType().getLabel(this.getUserObject());
	}
}
